﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Azku.Common;

namespace Azku.Common
{
    public class DataManager
    {
        private static DataManager m_Instance = null;
        private static Object m_LockObject = new Object();

        public static DataManager Instance
        {
            get
            {
                lock (m_LockObject)
                {
                    if (m_Instance == null)
                    {
                        m_Instance = new DataManager();
                    }
                }
                return m_Instance;
            }
        }
        
        private UserCollection m_UserCollection = new UserCollection();

        public UserCollection UserCollection
        {
            get { return m_UserCollection; }
            private set { m_UserCollection = value; }
        }

        private MessageCollection m_MessageCollection = new MessageCollection();

        public MessageCollection MessageCollection
        {
            get { return m_MessageCollection; }
            set { m_MessageCollection = value; }
        }


        private DataManager() { }

        public void InsertUser(User user)
        {
            if (m_UserCollection[user.UserName] == user)
            {
                UpdateUser(user);
            }
            else
            {
                m_UserCollection.Insert(user);
            }
        }
        public void UpdateUser(User user)
        {
            m_UserCollection.Update(user);
        }
        public void DeleteUser(User user)
        {
            m_UserCollection.Delete(user);
        }

        
    }
}
